package com.cw.jeeyt.service.converter.api;

import java.util.List;
import java.util.ArrayList;

import com.cw.jeeyt.service.bo.api.ApiFacadeGenerateConfigBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeGenerateConfigDo;
import com.cw.jeeyt.api.dto.facadeExcel.ApiGenerateFacadeExcelDto;
import com.cw.lang.common.utils.CollectionUtil;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

/**
 * 接口文档生成配置转换类
 *
 * @author chenw
 * @date 2020-04-19 17:18:55
 */
public class ApiFacadeGenerateConfigConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeGenerateConfigBo do2Bo(ApiFacadeGenerateConfigDo model) {
        ApiFacadeGenerateConfigBo bo = new ApiFacadeGenerateConfigBo();
        if (model == null) {
            return bo;
        }
        bo.setCreateTime(model.getCreateTime());
        bo.setEnumSacnPackage(model.getEnumSacnPackage());
        bo.setRpcType(model.getRpcType());
        bo.setEnumPatterns(model.getEnumPatterns());
        bo.setFacadeVersion(model.getFacadeVersion());
        bo.setFacadeFilePaths(model.getFacadeFilePaths());
        bo.setFacadeParamFilePaths(model.getFacadeParamFilePaths());
        bo.setFacadeUrlPrefix(model.getFacadeUrlPrefix());
        bo.setGenerateHeaderParam(model.getGenerateHeaderParam());
        bo.setId(model.getId());
        bo.setOutputPath(model.getOutputPath());
        bo.setProjectCode(model.getProjectCode());
        bo.setProjectName(model.getProjectName());
        bo.setTargetPath(model.getTargetPath());
        bo.setUpdateTime(model.getUpdateTime());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeGenerateConfigDo bo2Do(ApiFacadeGenerateConfigBo bo) {
        ApiFacadeGenerateConfigDo model = new ApiFacadeGenerateConfigDo();
        if (bo == null) {
            return model;
        }
        model.setCreateTime(bo.getCreateTime());
        model.setRpcType(bo.getRpcType());
        model.setEnumSacnPackage(bo.getEnumSacnPackage());
        model.setEnumPatterns(bo.getEnumPatterns());
        model.setFacadeVersion(bo.getFacadeVersion());
        model.setFacadeFilePaths(bo.getFacadeFilePaths());
        model.setFacadeParamFilePaths(bo.getFacadeParamFilePaths());
        model.setFacadeUrlPrefix(bo.getFacadeUrlPrefix());
        model.setGenerateHeaderParam(bo.getGenerateHeaderParam());
        model.setId(bo.getId());
        model.setOutputPath(bo.getOutputPath());
        model.setProjectCode(bo.getProjectCode());
        model.setProjectName(bo.getProjectName());
        model.setTargetPath(bo.getTargetPath());
        model.setUpdateTime(bo.getUpdateTime());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeGenerateConfigBo> doList2BoList(List<ApiFacadeGenerateConfigDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeGenerateConfigConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeGenerateConfigDo> boList2DoList(List<ApiFacadeGenerateConfigBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeGenerateConfigConverter::bo2Do));
    }

    public static ApiFacadeGenerateConfigDo facadeExcel2Do(ApiGenerateFacadeExcelDto facadeExcelDto) {
        ApiFacadeGenerateConfigDo configDo = new ApiFacadeGenerateConfigDo();
        configDo.setEnumSacnPackage(facadeExcelDto.getEnumSacnPackage());
        configDo.setEnumPatterns(facadeExcelDto.getEnumPatterns());
        configDo.setRpcType(facadeExcelDto.getRpcType());
        configDo.setFacadeFilePaths(facadeExcelDto.getFacadeFilePaths());
        configDo.setFacadeParamFilePaths(facadeExcelDto.getFacadeParamFilePaths());
        configDo.setFacadeUrlPrefix(facadeExcelDto.getFacadeUrlPrefix());
        configDo.setGenerateHeaderParam(facadeExcelDto.getGenerateHeaderParam());
        configDo.setOutputPath(facadeExcelDto.getOutputPath());
        configDo.setProjectCode(facadeExcelDto.getProjectCode());
        configDo.setProjectName(facadeExcelDto.getProjectName());
        configDo.setTargetPath(facadeExcelDto.getTargetPath());
        configDo.setFacadeVersion(facadeExcelDto.getFacadeVersion());
        return configDo;
    }
}